home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / UIFlow 1.0.1 / UIFlow Source / CFDFront / CFDFrontDocument.cp < prev    next >
Encoding:
Text File  |  1993-04-14  |  53.6 KB  |  1,499 lines  |  [TEXT/MPS ]

  1. #pragma segment UIFlow
  2. extern pascal int UIFLOW();
  3. extern "C" int ConvertVSet2Raster(char *);
  4. extern "C" int DFR8restart();
  5. extern "C" int DFR8getdims(char*,long*,long*,Boolean*);
  6. extern "C" int DFR8getimage(char*,char*,long,long,char*);
  7. extern "C" int DFR8lastref();
  8. extern "C" int DFANgetlabel(char*,int,int,char*,long);
  9. #include "::HDF3.1r4:Src:df.h"
  10.  
  11.  
  12. EventRecord * gEvent;
  13. short gStop;
  14. //**********************************************************************
  15. //    The TCFDFrontDocument class methods.    
  16. //**********************************************************************
  17. //    Prandlt Numbers    [0]    =    u
  18. //                                [1]    =    v
  19. //                                [2]    =    pressure
  20. //                                [3]    =    w
  21. //                                [4]    =    sigma h
  22. //                                [5]    =    kinetic energy
  23. //                                [6]    =    dissipation rate
  24. //                                [7]    =    sigma f
  25. //                                [8]    =    sigma fu
  26. //                                [9]    =    sigma g
  27. //                                [10]    =    density
  28. // -----------------------------------------------------------------------------------------
  29. //    Make the view for the document. This will create the geometry window
  30. // -----------------------------------------------------------------------------------------
  31. Boolean TCFDFrontDocument::ICFDFrontDocument (Boolean /*forPrinting*/)
  32. {
  33.     IDocument(kFileType,                                                                     // This document's file type.
  34.               kSignature,                                                                         // This document's creator.    
  35.               kUsesDataFork,                                                                     // This document does use the data fork    
  36.               ~kUsesRsrcFork,                                                                    // …but doesn't use the resource fork.    
  37.               ~kDataOpen,                                                                            // We don't want the data fork kept open
  38.               ~kRsrcOpen);                                                                        // …nor the resource fork.    
  39.  
  40.     fRemoteApplication[0] = 0;
  41.     fImageName[0]                    =    0;
  42.     fDataOpen     = FALSE;
  43.     fGridOperation = false;
  44.     fPrintOpts    = 0L;                                                                                // set all print options to off
  45.     fDialogOn        = 0L;    
  46.     fFlowOpts        = 5457L;                                                                        // set the correct radio buttons
  47.     fSolution[0]    = fSolution[1] = fSolution[2] = fSolution[3] = fSolution[4] = 1L;
  48.     fRelax[0]        = fRelax[1] = fRelax[3] = fRelax[4] = fRelax[5] = fRelax[6] = .5;
  49.     fRelax[2]         = .8;
  50.     fPran[0]        = fPran[1] = fPran[2] = fPran[3] = fPran[5] = fPran[10] = 1.0;
  51.     fPran[4]        = .7;
  52.     fPran[6]        = 1.3;
  53.     fPran[7]        = fPran[8] = fPran[9] = 0.9;
  54.     fBreakup        = 3.0;
  55.     fFuel             = 0;
  56.     fTempFuel    = fTempAir    = 300.00;
  57.     fSolutionAccuracy         = 0.0005;
  58.     fIteration                    = 100;
  59.     fBoundryRadius            = 0;
  60.     fPressure                        = 1.0000E+05;                                                    // pressure
  61.     fCompress                        = 0;                                                                    // incompressible
  62.     fWidth                            = 0;
  63.     fHeight                            = 0;
  64.     fUnitFraction                = 0;
  65.     fInterior                        = NULL;
  66.     gFortranView                = NULL;
  67.  
  68.     fMakeView                        = false;
  69.     fExport                            = 0;
  70.     gEvent                            = NULL;
  71.  
  72.     TWindow * aWindow;
  73.     aWindow = NewTemplateWindow(kCFDFrontWindowId, (TDocument *)this);    // create geomview
  74.     FailNIL (aWindow);                                                                                // enough memory?
  75.         
  76.     fGeom = (TGeomView *)(aWindow->FindSubView ('geom'));            // find geom subview
  77.     fPointMatrix    = new TPointMatrix;                                                    // create the matrix list
  78.     FailNIL(fPointMatrix);                                                                        // error?
  79.     fPointMatrix->IPointMatrix(this,fGeom);                                        // initialize the list
  80.  
  81.     fInterior = new TInteriorPoint;                                                        // create a pt which represents interior
  82.     fInterior->IPoint(0,0,Grid,0);                                                        // initialize new point
  83.         
  84.     return true;
  85.     }
  86.  
  87. // -----------------------------------------------------------------------------------------
  88. //    Make the view for the document. This will create the geometry window
  89. // -----------------------------------------------------------------------------------------
  90. TCFDFrontDocument::TCFDFrontDocument ()    
  91.     {
  92.     fMouseAction = 0;
  93.     }
  94.  
  95. // -----------------------------------------------------------------------------------------
  96. //    Free all things allocated with New
  97. // -----------------------------------------------------------------------------------------
  98. pascal void TCFDFrontDocument::Free(void)
  99.     {
  100. //    FreeIfObject(fPointMatrix);
  101. //    FreeIfObject(fInterior);
  102.     inherited::Free();
  103.     }
  104.     
  105. // --------------------------------------------------------------------------------------------------
  106. //    this routine will make a new geometry document
  107. // --------------------------------------------------------------------------------------------------
  108. pascal struct TDocument * TCFDFrontApplication::DoMakeDocument (CmdNumber /*itsCmdNumber*/)
  109.     {
  110.     TCFDFrontDocument    *anCFDFrontDocument;
  111.     
  112.     anCFDFrontDocument = new TCFDFrontDocument;    
  113.     anCFDFrontDocument->ICFDFrontDocument(false);                                            // …nor the resource fork.    
  114.             
  115.     FailNIL(anCFDFrontDocument);    
  116.     return (struct TDocument *) anCFDFrontDocument;
  117.     }
  118.  
  119. // -----------------------------------------------------------------------------------------
  120. //    Make the view for the document. This will create the geometry window
  121. // -----------------------------------------------------------------------------------------
  122. pascal void TCFDFrontDocument::DoMakeViews (Boolean /*forPrinting*/)
  123.     {
  124.     TWindow        *aWindow;
  125.     Point             miSize, maSize;
  126.         
  127. //    if (fMakeView)
  128. //        return;
  129.         
  130.     if (!gCFDFrontApplication->fReadOld)
  131.         this->GetDims();                                                                                // get the dimensions of the geometry
  132.     
  133.     aWindow = (TWindow *) fGeom->GetWindow();
  134.     fGeom->SetGeomViewSize ();                                                                // set the geometry size
  135.     maSize.h = aWindow->fResizeLimits.right;                                    // restrict the size user can
  136.     maSize.v = aWindow->fResizeLimits.bottom;                                    // shrink the window to.
  137.     miSize.h  = 300;
  138.     miSize.v = 300;
  139.     aWindow->SetResizeLimits(miSize,maSize);
  140.     if (!gCFDFrontApplication->fReadOld)
  141.         fPointMatrix->InitCorners();
  142.  
  143.     fDataView = (TDataView *)(aWindow->FindSubView('DATA'));    // init the data view object
  144.     fDataView->IDataView();                                                                        // init the data view
  145.     
  146.     fInfoView = (TInformationView *)(aWindow->FindSubView ('info'));    // create TInformationView
  147.     fInfoView->IInformationView(this);
  148.     gInfoView = fInfoView;
  149.     
  150.     fMakeView = true;
  151.     }
  152.     
  153. // -----------------------------------------------------------------------------------------
  154. //    set the mouse action mode.
  155. // -----------------------------------------------------------------------------------------
  156. void TCFDFrontDocument::SetMouseAction (IDType op)    
  157.     {
  158.     // fMouseAction is the zero based index that indicates what
  159.     //    mouse action mode we are in.
  160.     fMouseAction = (short) ((long) op  - (long) 'Ops1');
  161.     }
  162.  
  163. // -----------------------------------------------------------------------------------------
  164. //    Enable and disable menu items for this kind of document
  165. // -----------------------------------------------------------------------------------------
  166. pascal void TCFDFrontDocument::DoSetupMenus (void)
  167.     {
  168. //     Enable the new menu item
  169.     inherited::DoSetupMenus();
  170.     for (short menuIndex = cFirst; menuIndex <= cLast; menuIndex++)
  171.         Enable(menuIndex,true);
  172.     }
  173.  
  174. // -----------------------------------------------------------------------------------------
  175. //     Convert view coordinate to real coordinates
  176. // -----------------------------------------------------------------------------------------
  177. void TCFDFrontDocument::ViewToReal (Point thePoint, struct realPt * realNum)
  178.     {
  179.     realNum->x = (float) (thePoint.h - cGeomViewBorder);            // convert the x component
  180.     realNum->x *= fUnitFraction;
  181.     realNum->y = (float) (cMaxSize+cGeomViewBorder - thePoint.v);    // convert the y component
  182.     realNum->y *= fUnitFraction;
  183.     return;
  184.     }
  185.  
  186. // -----------------------------------------------------------------------------------------
  187. //     Convert real coordinate to view coordinates
  188. // -----------------------------------------------------------------------------------------
  189. Point TCFDFrontDocument::RealToView (struct realPt * realNum)
  190.     {
  191.     Point newPoint;
  192.     char XP[20], YP[20];
  193.     
  194.     sprintf(XP,"%.4f",realNum->x);                                                        // store values for warning message
  195.     sprintf(YP,"%.4f",realNum->y);
  196.     realNum->x /= fUnitFraction;                                                            // convert the x component
  197.     realNum->x += (float) cGeomViewBorder;
  198.     realNum->y /= (fUnitFraction * -1);                                                // convert the y component
  199.     realNum->y += (float) (cMaxSize+cGeomViewBorder);
  200.  
  201.     newPoint.h = (short) realNum->x;                                                    // store x in newPoint
  202.     newPoint.v = (short) realNum->y;                                                    // store y in newPoint
  203.         
  204.     if (newPoint.h > cMaxSize || newPoint.v > cMaxSize)                // within boundries?
  205.         {
  206.         TWindow    * aWindow;                                                                            // warning window
  207.         TWarning    * theWarning;                                                                    // warning object
  208.         char warning[40];                                                                                // no : give warning message
  209.         sprintf(warning,"%s = %d  :   %s = %d",XP,newPoint.h,YP,newPoint.v); // create warning message
  210.         aWindow = NewTemplateWindow(kWarnMe,this);                            // create window
  211.         theWarning = (TWarning *) aWindow->FindSubView('WARN');    // get pointer to object
  212.         theWarning->IWarning(0,warning);                                                // initialize the warning
  213.         theWarning->ShowWarning();                                                            // display the warning
  214.         newPoint.v = NULL;                                                                            // set NULL for return
  215.         }
  216.     return newPoint;                                                                                    // return the point
  217.     }
  218.         
  219. // -----------------------------------------------------------------------------------------
  220. //    Process the Menu Commands
  221. // -----------------------------------------------------------------------------------------
  222. pascal void TCFDFrontDocument::Close(void)
  223.     {
  224.     fPass            = 1;
  225.     fExport            = 0;
  226.     fWriteGrid    = true;
  227.     inherited::Close();
  228.     }
  229.     
  230. // -----------------------------------------------------------------------------------------
  231. //    Process the Menu Commands
  232. // -----------------------------------------------------------------------------------------
  233. pascal TCommand* TCFDFrontDocument::DoMenuCommand(CmdNumber aCmdNumber)
  234.     {
  235.     switch (aCmdNumber)
  236.         {
  237.         case cSave:
  238.         case cSaveAs:
  239.         case cSaveCopy:
  240.             {
  241.             fOutput = new TFOutput;
  242.             if (fOutput == NULL)                                                                // LAM - error message
  243.                 break;
  244.             
  245.             fOutput->IOutput(this,true);
  246.             fPass            = 1;
  247.             fExport            = 1;
  248.             fWriteGrid    = true;
  249.             return inherited::DoMenuCommand(aCmdNumber);
  250.             }
  251.         case cExport:
  252.             {
  253.             char        sTitle[255], *s;                                                    // temp storage file name
  254.             char        tTitle[225];
  255.             char        gTitle[225];
  256.             char     msg[80];
  257.             short    sRefNum, bRef, bRsrc;                                                // temp storage volume reference
  258.  
  259.             StringPtr volume, name, gname;
  260.             short refNum;
  261.             OSErr    error;
  262.             
  263.             fOutput = new TFOutput;
  264.             if (fOutput == NULL)                                                            // LAM - error message
  265.                 break;
  266.             
  267.             fOutput->IOutput(this,false);
  268.  
  269.             sprintf(msg,"Creating UIFlow.In & UIFlow.Grid");     // give message
  270.             fInfoView->InfoString(msg);
  271.             
  272.             bRef     = fDataRefnum;
  273.             bRsrc    = fRsrcRefnum;
  274.             sprintf(msg,"Export Operation Complete");                     // give message
  275. //            strcpy(sTitle,(char *) fTitle);                                        // store the file name
  276.             s = p2cstr(*fTitle);
  277.             strcpy(sTitle,s);
  278.                  
  279.             sprintf(tTitle,"UIFlow.In");
  280.             name = c2pstr(tTitle);
  281.             sprintf(gTitle,"UIFlow.Grid");
  282.             gname = c2pstr(gTitle);
  283.  
  284.             fFileType = 'TEXT';
  285.             this->SetTitle(name);                                                            // store the name    
  286.             volume        = c2pstr("test");
  287.             sRefNum    = fVolRefNum;                                                            // store the volume
  288.             HLock((Handle) this);
  289.             GetVol(volume,&refNum);                                                        // get volumne information
  290.             HUnlock((Handle) this);
  291.             fVolRefNum = refNum;                                                            // store volume
  292.  
  293.             error             = FSDelete(name,refNum);                            // delete old input deck
  294.             fPass                = 1;
  295.             fWriteGrid    = false;                                                            // write on second pass
  296.             fExport            = 2;
  297.             this->Save(aCmdNumber,false,true);                                // save file
  298.  
  299.             this->SetTitle(gname);                                                        // store the name
  300.  
  301.             error = FSDelete(gname,refNum);                                        // delete old input deck
  302.             fChangeCount++;                                                                        // flag to save
  303.             fPass            = 2;
  304.             fWriteGrid    = true;                                                                // write on second pass
  305.             this->Save(aCmdNumber,false,true);                                // save file
  306.             
  307.             fFileType        =    kFileType;
  308.             name                 = c2pstr(sTitle);
  309.             this->SetTitle(name);                                                            // store the name    
  310.             fPass                = 1;
  311.             fExport            = 0;
  312.             fWriteGrid    = false;
  313.             
  314.             CloseFile(fDataRefnum, fRsrcRefnum);
  315.             fDataRefnum = bRef;
  316.             fRsrcRefnum    = bRsrc;
  317.             
  318.             FreeIfObject(fOutput);
  319.             fInfoView->InfoString(msg);
  320.             break;
  321.             }
  322.         case cGridOn:                                                                                // create grid option
  323.             {
  324.             char            string[80];
  325.             StringPtr    pString;
  326.                 
  327.             if (!fPointMatrix->IsShown())
  328.                 sprintf(string,"Hide Grid");
  329.             else
  330.                 sprintf(string,"Show Grid");                
  331.  
  332.             pString = c2pstr(string);
  333.             SetCmdName(cGridOn,pString);
  334.             if (fGeom->fSPoint != NULL)
  335.                 {
  336.                 if (fGeom->fSPoint->IsInterior())
  337.                     {
  338.                     fPointMatrix->DoHighlight();
  339.                     fGeom->UnSelect();
  340.                     }
  341.                 }
  342.             fPointMatrix->DoDrawGrid();
  343.             break;
  344.             }            
  345.         case cOptPrint :
  346.             this->MakeOptPrint();
  347.             break;
  348.         case cOptRelax :
  349.             this->MakeOptRelax();
  350.             break;
  351.         case cOptSolution :
  352.             this->MakeOptSolution();
  353.             break;
  354.         case cOptFlow :
  355.             this->MakeOptFlow();
  356.             break;
  357.         
  358.         case cRApp :
  359.             this->GetRemoteApp();
  360.             break;
  361.  
  362.         case cRemote :
  363.             {
  364.             }
  365.             
  366.         case cLocal:
  367.             {
  368.             char        sTitle[255], *s;                                                            // temp storage file name
  369.             char        tTitle[225];
  370.             char        gTitle[225];
  371.             char        vTitle[225];
  372.             char        image[225];
  373.             char     msg[80], msg1[80], msg2[80], msg3[80], msg4[80];
  374.             short    sRefNum, bRef, bRsrc;                                                // temp storage volume reference
  375.             StringPtr volume, name, gname, vname;
  376.             short refNum;
  377.             OSErr    error;
  378.             
  379.             this->GetImageName();
  380.             fOutput = new TFOutput;
  381.             if (fOutput == NULL)                                                            // LAM - error message
  382.                 break;
  383.             
  384.             fOutput->IOutput(this,false);
  385.  
  386.             sprintf(msg,"Creating UIFlow.In & UIFlow.Grid");     // give message
  387.             fInfoView->InfoString(msg);
  388.             
  389.             bRef     = fDataRefnum;
  390.             bRsrc    = fRsrcRefnum;
  391.  
  392.             sprintf(msg,"Export Operation Complete");                     // give message
  393.             sprintf(msg1,"Converting Output to Raster Image");// give message
  394.             sprintf(msg2,"Raster Image is Available in File %s",fImageName);// give message
  395.             sprintf(msg3,"VSet File is Corrupted");                        // give message
  396.             sprintf(msg4,"Unable to Create Raster");                    // give message
  397.             s = p2cstr(*fTitle);
  398.             strcpy(sTitle,s);
  399.             sprintf(tTitle,"UIFlow.In");
  400.             name = c2pstr(tTitle);
  401.             sprintf(gTitle,"UIFlow.Grid");
  402.             gname = c2pstr(gTitle);
  403.             sprintf(vTitle,"vset.out");
  404.             vname = c2pstr(vTitle);
  405.  
  406.             fFileType = 'TEXT';
  407.             this->SetTitle(name);                                                            // store the name    
  408.             volume        = c2pstr("test");
  409.             sRefNum    = fVolRefNum;                                                            // store the volume
  410.             HLock((Handle) this);
  411.             GetVol(volume,&refNum);                                                        // get volumne information
  412.             HUnlock((Handle) this);
  413.             fVolRefNum = refNum;                                                            // store volume
  414.  
  415.             error = FSDelete(vname,refNum);                                        // delete the old vset
  416.             error = FSDelete(name,refNum);                                        // delete old input deck
  417.             fPass            = 1;
  418.             fWriteGrid    = false;                                                            // write on second pass
  419.             fExport            = 2;
  420.             this->Save(aCmdNumber,false,true);                                // save file
  421.  
  422.             this->SetTitle(gname);                                                        // store the name
  423.  
  424.             error = FSDelete(gname,refNum);                                        // delete old input deck
  425.             fChangeCount++;                                                                        // flag to save
  426.             fPass            = 2;
  427.             fWriteGrid    = true;                                                                // write on second pass
  428.             this->Save(aCmdNumber,false,true);                                // save file
  429.             
  430.             fFileType        =    kFileType;
  431.             name                 = c2pstr(sTitle);
  432.             this->SetTitle(name);                                                            // store the name    
  433.             fPass                = 1;
  434.             fExport            = 0;
  435.             fWriteGrid    = false;
  436.             
  437.             CloseFile(fDataRefnum, fRsrcRefnum);
  438.             fDataRefnum = bRef;
  439.             fRsrcRefnum    = bRsrc;
  440.             
  441.             FreeIfObject(fOutput);
  442.             fInfoView->InfoString(msg);
  443.  
  444.             if (gFortranView == NULL)
  445.                 this->MakeFortranWindow();
  446.             else
  447.                 {
  448.                 TWindow * aWindow;    
  449.                 char  string[20];
  450.                 StringPtr pString;
  451.                 
  452.                 aWindow = gFortranView->GetWindow();
  453.                 aWindow->Select();
  454.                 string[0] = 0;                                                                        // convert the data to string
  455.                 pString = c2pstr(string);                                                    // convert to pascal type
  456.                 gFortranView->SetText(pString);
  457.                 }
  458.  
  459.             Boolean      ispal;
  460.             long            i, j;
  461.             int                 ref;
  462.             char            label[79];
  463.             char             * data;
  464. //            TDataTransport * dTm;                                                                // dtm connection
  465.  
  466.             gEvent = new EventRecord;
  467.             gStop  = 0;
  468.           HLock((Handle) gFortranView);
  469.                 UIFLOW();
  470.           HUnlock((Handle) gFortranView);
  471.             delete gEvent;
  472.             if (gStop == 0)
  473.                 {
  474.                 fInfoView->InfoString(msg1);
  475.                 switch (ConvertVSet2Raster(fImageName))
  476.                     {
  477.                     case -1:
  478.                         fInfoView->InfoString(msg4);
  479.                         FailNIL (0);
  480.                         break;
  481.                     case -2:
  482.                         fInfoView->InfoString(msg3);
  483.                         FailNIL (0);
  484.                         break;
  485.                     } 
  486.                         
  487. /*                data[0] = 0;
  488.               HLock((Handle) this);
  489.                 dTm = new TDataTransport;
  490.                 FailNIL(data);
  491.                 
  492.                 DFR8restart();                                                                      // start from the begining of the file
  493.                  while (0 <= DFR8getdims(fImageName, &i, &j, &ispal))    
  494.                      {
  495.                     data = new char[i*j+10];
  496.                     FailNIL(data);
  497.                     DFR8getimage(fImageName, data, i, j, NULL);
  498.                     if (ispal)
  499.                         {}                                                                                        // send palette - is none
  500.                     ref = DFR8lastref ();
  501.                     DFANgetlabel (fImageName, (int) DFTAG_RIG, ref, label,80);
  502.                     dTm->Send2DByteData(data,(int)i,(int)j,label);
  503.                     }
  504.               HUnlock((Handle) this); */
  505.                 }
  506.             else
  507.                 fInfoView->InfoString(msg2);
  508.             
  509.             break;
  510.             }
  511.             
  512.         case cQuit:
  513.             return inherited::DoMenuCommand(aCmdNumber);
  514.                     
  515.         default :
  516.             return inherited::DoMenuCommand(aCmdNumber);                // all others
  517.         }            
  518.     return gNoChanges;
  519.     }
  520.  
  521. pascal void TCFDFrontDocument::Save(CmdNumber itsCmdNumber, Boolean askForFilename, Boolean makingCopy)
  522.     {
  523.     inherited::Save(itsCmdNumber,askForFilename,makingCopy);
  524.     if (fExport == 1)
  525.         {
  526.         FreeIfObject(fOutput);                                                                // free the space
  527.         fOutput = NULL;                                                                                // null the var
  528.         }
  529.     }
  530.     
  531. pascal void TCFDFrontDocument::ReadFromFile(AppFile *anAppFile, Boolean forPrinting)
  532.     {
  533. //    this->DoMakeViews(false);                                                            // make view
  534.     inherited::ReadFromFile(anAppFile,forPrinting);
  535.     }
  536.     
  537. // -----------------------------------------------------------------------------------------
  538. //    Read the file
  539. // -----------------------------------------------------------------------------------------
  540. pascal void TCFDFrontDocument::DoRead(short aRefNum, Boolean /*rsrcExists*/, Boolean /*forPrinting*/)
  541.     {
  542.     char     * buff, s[80];
  543.     Boolean    flowOpts[15], printOpts[13];
  544.     short    i, t1;
  545.     short    gRow, gColumn;                                                                            // number rows & columns
  546.     long        t2;
  547.     WallRecord data;
  548.         
  549.     flowOpts[0] = flowOpts[1] = flowOpts[2] = flowOpts[3] = flowOpts[4] = flowOpts[5] = false;
  550.     flowOpts[6] = flowOpts[7] = flowOpts[8] = flowOpts[9] = flowOpts[10] = flowOpts[11]  = false;
  551.     flowOpts[12] = flowOpts[13] = flowOpts[14] = false;
  552.     printOpts[0] = printOpts[1] = printOpts[2] = printOpts[3] = printOpts[4] = printOpts[5] = printOpts[6] = false;
  553.     printOpts[7] = printOpts[8] = printOpts[9] = printOpts[10] = printOpts[11] = printOpts[12] = false;
  554.  
  555. //    FailOSErr(GetEOF(aRefNum, &numChars));                                    // Read in the text 
  556.  
  557.     buff = new char[514];
  558.     FailMemError();
  559.     buff[0]    = 0;
  560.  
  561. //    line 1         ....................................................................
  562.     this->ReadLine(aRefNum, buff, s);                                                    // fWidth
  563.     fWidth = atof(s);
  564.     this->ReadLine(aRefNum, buff, s);                                                    // fHeight
  565.     fHeight = atof(s);
  566.     this->ReadLine(aRefNum, buff, s);                                                    // fUnitFraction
  567.     fUnitFraction = atof(s);
  568.  
  569.     this->ReadLine(aRefNum, buff, s);                                                    // klam    -    laminar flow
  570.     t1 = atoi(s);
  571.     if (t1 == 0)                                                                                            // set laminar
  572.         flowOpts[5] = true;
  573.     else                                                                                                            // set turbulent
  574.         flowOpts[4] = true;
  575.         
  576.     this->ReadLine(aRefNum, buff, s);                                                    // kcomp    -    compressible flow
  577.     t1 = atoi(s);
  578.     fCompress = t1;
  579.         
  580.     this->ReadLine(aRefNum, buff, s);                                                    // kswrl    -    swirl / nonswirl
  581.     t1 = atoi(s);
  582.     if (t1 == 0)
  583.         flowOpts[8] = true;                                                                            // nonswirling
  584.     else
  585.         flowOpts[9] = true;                                                                            // swirling
  586.     
  587.     this->ReadLine(aRefNum, buff, s);                                                    // kpgrid    -    UIFlow Grid / external grid
  588.     t1 = atoi(s);
  589.     if (t1 == 0)
  590.         flowOpts[11] = true;
  591.     else
  592.         flowOpts[10] = true;
  593.         
  594.     this->ReadLine(aRefNum, buff, s);                                                    // model    -    model number
  595.     t1 = atoi(s);
  596.     flowOpts[t1] = true;                                                                            // turn on model
  597.     
  598. //    line 2         ....................................................................
  599.     this->ReadLine(aRefNum, buff, s);                                                        // kfuel    -    fuel type
  600.     t1 = atoi(s);
  601.     fFuel = t1;
  602.     
  603.     this->ReadLine(aRefNum, buff, s);                                                        // knorth    -    always 0 - not stored
  604.     this->ReadLine(aRefNum, buff, s);                                                        // kplax    -    planar[1] / axisymmetric [0]
  605.     t1 = atoi(s);
  606.     if (t1 == 0)
  607.         flowOpts[7] = true;
  608.     else
  609.         flowOpts[6] = true;
  610.         
  611.     this->ReadLine(aRefNum, buff, s);                                                        // kadjst    -    Blocked adjustment
  612.     t1 = atoi(s);
  613.     if (t1 == 0)
  614.         flowOpts[13] = true;
  615.     else
  616.         flowOpts[12] = true;
  617.     
  618. //    line 3         ....................................................................
  619.     this->ReadLine(aRefNum, buff, s);                                                        // ngrid    -    number of fine grid cells
  620.     t2 = atol(s);
  621.     fSolution[0] = t2;
  622.     t2--;
  623.     
  624.     this->ReadLine(aRefNum, buff, s);                                                        // ncelx    -    number of columns
  625.     t1 = atoi(s);
  626.     gColumn = (short) (t1 / (pow(2,t2))) + 1;
  627.     
  628.     this->ReadLine(aRefNum, buff, s);                                                        // ncely     -    number of rows
  629.     t1 = atoi(s);
  630.     gRow = (short) (t1 / (pow(2,t2))) + 1;
  631.     
  632.     
  633. //    line 4 +        ....................................................................
  634.     fPointMatrix->ReadSegment(cLeft, aRefNum, buff, gRow);
  635.     fPointMatrix->ReadSegment(cRight, aRefNum, buff, gRow);
  636.     fPointMatrix->ReadSegment(cBottom, aRefNum, buff, gColumn);
  637.     fPointMatrix->ReadSegment(cTop, aRefNum, buff, gColumn);
  638.     fPointMatrix->FillGrid(gRow, gColumn);
  639.     
  640. //    Interior Data    ....................................................................
  641.     this->ReadLine(aRefNum, buff, s);                                                            // u            -    u velocity
  642.     data.u = atof(s);
  643.     this->ReadLine(aRefNum, buff, s);                                                            // v            -    v velocity
  644.     data.v = atof(s);
  645.     this->ReadLine(aRefNum, buff, s);                                                            // w        -    w velocity
  646.     data.w = atof(s);
  647.     this->ReadLine(aRefNum, buff, s);                                                            // rh        -    density
  648.     data.density = atof(s);
  649.     this->ReadLine(aRefNum, buff, s);                                                            // t            -    temperature
  650.     data.temp = atof(s);
  651.     this->ReadLine(aRefNum, buff, s);                                                            // tk        -    kinetic energy
  652.     data.kenergy = atof(s);
  653.     this->ReadLine(aRefNum, buff, s);                                                            // td        -    dissipation
  654.     data.dissip = atof(s);
  655.     this->ReadLine(aRefNum, buff, s);                                                            // f            -    mixture fraction
  656.     data.mixfrac = atof(s);
  657.     this->ReadLine(aRefNum, buff, s);                                                            // g            -    concentration fraction
  658.     data.concfrac = atof(s);
  659.     this->ReadLine(aRefNum, buff, s);                                                            // fu        -    fuel fraction
  660.     data.fuelfrac = atof(s);
  661.     
  662.     this->ReadLine(aRefNum, buff, s);                                                            // tfuel    -     temperature fuel
  663.     fTempFuel = atof(s);
  664.     this->ReadLine(aRefNum, buff, s);                                                            // tair        -    temperature air
  665.     fTempAir = atof(s);
  666.     
  667. //    Prandtl Numbers    ....................................................................
  668.     for (i = 0; i < 11; i++)                                                                            // read prandtl numbers
  669.         {
  670.         this->ReadLine(aRefNum, buff, s);                                                        // get the value
  671.         fPran[i] = atof(s);                                                                            // convert number
  672.         }
  673.     for (i = 0; i < 11; i++)                                                                            // extra line prandtl numbers
  674.         this->ReadLine(aRefNum, buff, s);
  675.         
  676. //    Relaxation Numbers    ....................................................................
  677.     this->ReadLine(aRefNum, buff, s);                                                            // relx1    -    u velocity
  678.     fRelax[0] = atof(s);
  679.     this->ReadLine(aRefNum, buff, s);                                                            // relx2    -    v velocity
  680.     fRelax[1] = atof(s);
  681.     this->ReadLine(aRefNum, buff, s);                                                            // relx3    -    pressure
  682.     fRelax[2] = atof(s);
  683.     this->ReadLine(aRefNum, buff, s);                                                            // relx4    -    w velocity
  684.     fRelax[3] = atof(s);
  685.     this->ReadLine(aRefNum, buff, s);                                                            // relx5    -    h = scalar
  686.     fRelax[6] = atof(s);
  687.     this->ReadLine(aRefNum, buff, s);                                                            // relx6    -    kinetic energy
  688.     fRelax[4] = atof(s);
  689.     this->ReadLine(aRefNum, buff, s);                                                            // relx7    -    dissipation = kinetic energy
  690.     this->ReadLine(aRefNum, buff, s);                                                            // relx8    -    f = scalar
  691.     this->ReadLine(aRefNum, buff, s);                                                            // relx9    -    fu = scalar
  692.     this->ReadLine(aRefNum, buff, s);                                                            // relx10    -    g = scalar
  693.     this->ReadLine(aRefNum, buff, s);                                                            // relx11    -    density
  694.     fRelax[5] = atof(s);
  695.     
  696. //    Sweep Numbers    ....................................................................
  697.     this->ReadLine(aRefNum, buff, s);                                                            // nswp1    -    momentum
  698.     fSolution[1] = atof(s);
  699.     this->ReadLine(aRefNum, buff, s);                                                            // nswp2    -    momentum
  700.     this->ReadLine(aRefNum, buff, s);                                                            // nswp3    -    pressure corrections
  701.     fSolution[2] = atof(s);
  702.     this->ReadLine(aRefNum, buff, s);                                                            // nswp4    -    momentum
  703.     this->ReadLine(aRefNum, buff, s);                                                            // nswp5    -    scalar
  704.     fSolution[3] = atof(s);
  705.     this->ReadLine(aRefNum, buff, s);                                                            // nswp6    -    scalar
  706.     this->ReadLine(aRefNum, buff, s);                                                            // nswp7    -    scalar
  707.     this->ReadLine(aRefNum, buff, s);                                                            // nswp8    -    scalar
  708.     this->ReadLine(aRefNum, buff, s);                                                            // nswp9    -    scalar
  709.     this->ReadLine(aRefNum, buff, s);                                                            // nswp10-    scalar
  710.     this->ReadLine(aRefNum, buff, s);                                                            // nswp11-    scalar
  711.  
  712. //    Print Variables    ....................................................................
  713.     for (i = 0; i < 12; i++)
  714.         {
  715.         this->ReadLine(aRefNum, buff, s);                                                        // iprint    -    print variables
  716.         t1 = atoi(s);
  717.         if (t1 == 1)
  718.             printOpts[i] = true;
  719.         }
  720.     HLock((Handle) this);
  721.     this->EncodeParam(14,flowOpts,&fFlowOpts);                                        // encode the booleans
  722.     this->EncodeParam(12,printOpts,&fPrintOpts);    
  723.     HUnlock((Handle) this);
  724.  
  725. //    Miscellaneous Variables    ....................................................................
  726.     this->ReadLine(aRefNum, buff, s);                                                            // refp        -    system pressure
  727.     fPressure = atol(s);
  728.     this->ReadLine(aRefNum, buff, s);                                                            // vscty    -    internal viscosity
  729.     data.visc     = atof(s);
  730.     fInterior->SetData(data);                                                                        // store the data
  731.     this->ReadLine(aRefNum, buff, s);                                                            // maxi    -    maximum iterations
  732.     fIteration = atoi(s);
  733.     this->ReadLine(aRefNum, buff, s);                                                            // tolr        -    solution accuracy
  734.     fSolutionAccuracy = atof(s);
  735.     this->ReadLine(aRefNum, buff, s);                                                            // rn        -    boundry radius
  736.     fBoundryRadius = atof(s);
  737.     
  738. //    Obstacles & Baffles        ....................................................................
  739.     fPointMatrix->ReadObstructions(aRefNum, buff);
  740.  
  741. //    Grid Point Locations        ....................................................................
  742.     fPointMatrix->ReadGrid(aRefNum, buff);
  743.     delete buff;
  744.     return;
  745.     }
  746.  
  747. // -----------------------------------------------------------------------------------------
  748. //    Read the file
  749. // -----------------------------------------------------------------------------------------
  750. Boolean TCFDFrontDocument::ReadLine(short aRefNum, char * buff, char * string)
  751.     {
  752.     short     l, t, i, ii;
  753.     long         pos, eof;
  754.     short    mode;
  755.     
  756.     t = strlen(buff);
  757.     mode = fsFromMark;
  758.     if (t == 0)
  759.         {
  760.         long numChars;
  761.         numChars = 512L;
  762.         
  763.         HLock((Handle) this);
  764.         GetEOF(aRefNum, &eof);
  765.         GetFPos(aRefNum, &pos);
  766.         HUnlock((Handle) this);
  767.         
  768.         if (pos+512 > eof)
  769.             numChars = eof - pos;
  770.  
  771.         HLock((Handle) this);
  772.         FailOSErr(FSRead(aRefNum, &numChars, buff));
  773.         HUnlock((Handle) this);
  774.         
  775.         if (numChars == 512 )
  776.             {
  777.             i = 0;
  778.             ii = (short) numChars;
  779.             while (buff[ii] != ' ')
  780.                 {
  781.                 i++;
  782.                 ii--;
  783.                 }
  784.             buff[ii] = 0;
  785.             SetFPos(aRefNum,mode,(long) (-1 * (i-1)));
  786.             }
  787.         t = strlen(buff);
  788.         }
  789.     
  790.     sscanf (buff, "%s",string);
  791.     l = strlen(string);
  792.     string[l+1] = 0;
  793.     for (i = l+1;  i <= t; i++)
  794.         buff[i-l-1] = buff[i];
  795.     buff[i-l-1] = 0;
  796.     
  797.     return true;
  798.     }
  799.         
  800. // -----------------------------------------------------------------------------------------
  801. //    Add End
  802. // -----------------------------------------------------------------------------------------
  803. void TCFDFrontDocument::AddTerminator(char * string)
  804.     {
  805.     switch(fExport)
  806.         {
  807.         case 1:
  808.             strcpy(string,"\n");
  809.             return;
  810.         case 2:
  811.             strcpy(string,"/\n");
  812.             return;
  813.         case 3:
  814.             strcpy(string,"/");
  815.             return;
  816.         }
  817.     }
  818.         
  819. // -----------------------------------------------------------------------------------------
  820. //    Write the file
  821. // -----------------------------------------------------------------------------------------
  822. pascal void TCFDFrontDocument::DoWrite(short aRefNum, Boolean /*makingCopy*/)
  823.     {
  824.     char     * string, sEnd[4];
  825.     short    i, x, n;
  826.     long        temp;
  827.     Boolean flowOpt[15], printOpt[13];
  828.     
  829.     string = new char[80];
  830.     
  831.     HLock((Handle) this);
  832.     this->AddTerminator(sEnd);
  833.     HUnlock((Handle) this);
  834.     
  835.     if (fPass == 1)
  836.         {
  837.         if (fExport == 1)
  838.             {
  839.             i = sprintf(string,"%f ",fWidth);
  840.             i += sprintf(string+i,"%f ",fHeight);
  841.             i += sprintf(string+i,"%f\n",fUnitFraction);
  842.             fOutput->Write(aRefNum,string);
  843.             }
  844.             
  845. //    write the global information first
  846. //    line 1    ................................    
  847.         this->DecodeParam(14,flowOpt,fFlowOpts);                                // decode the flow parameters
  848.         i = sprintf(string,"%d ",flowOpt[4]);                                        // klam    - laminar flow
  849.         if (flowOpt[1])
  850.             i += sprintf(string+i,"1 ");                                                    // kcomp    - compressible
  851.         else
  852.             i += sprintf(string+i,"0 ");                                                    // kcomp    - incompressible
  853.         i += sprintf(string+i,"%d ",flowOpt[9]);                                    // kswrl    - nonswirl [0] / swirl [1]
  854.         if (flowOpt[10])
  855.             i += sprintf(string+i,"1 ");                                                    // kpgrid    - created by UIFlow
  856.         else
  857.             i += sprintf(string+i,"0 ");                                                    // kpgrid    - not created by UIFlow
  858.         for (x = 0; x <= 3; x++)                                                                // model    - which model?
  859.             {
  860.             if (flowOpt[x])
  861.                 i += sprintf(string+i,"%d",x);                                            // model
  862.             }
  863.         sprintf(string+i,"%s",sEnd);                                                        // model
  864.         fOutput->Write(aRefNum,string);
  865.  
  866. //    line 2    ................................    
  867.         i = sprintf(string,"%d ",fFuel);                                                // kfuel    - fuel type
  868.         i += sprintf(string+i,"0 ");                                                        // knorth    - (always = 0)
  869.         i += sprintf(string+i,"%d ",flowOpt[6]);                                // kplax    - planar [1] / axisymmetric [0]
  870.         if (flowOpt[12])
  871.             i += sprintf(string+i,"1 ");                                                    // kadjst    - Block adjustment
  872.         else
  873.             i += sprintf(string+i,"0 ");                                                    // kadjst    - No Block adjustment
  874.  
  875.         sprintf(string+i,"%s",sEnd);                                                        // model
  876.         fOutput->Write(aRefNum,string);
  877.  
  878. //    line 3    ................................    
  879.         n = (short) fSolution[0];
  880.         i = sprintf(string,"%d ",n);                                                        // ngrid    - number of fine grids
  881.         n--;
  882.         x = fPointMatrix->GetTColumn() - 1;                                            // get number of columns
  883.         temp = (pow(2,n)) * x;                                                                    // number of fine grid cells - x direction
  884.         i += sprintf(string+i,"%ld ",temp);                                            // ncelx    - number fine grid cells - x direction
  885.         x = (short) fPointMatrix->GetSize() - 1;                                // get number of rows
  886.         temp = (pow(2,n)) * x;                                                                    // number of fine grid cells - y direction
  887.         i += sprintf(string+i,"%ld",temp);                                            // ncely    - number fine grid cells - y direction
  888.  
  889.         sprintf(string+i,"%s",sEnd);                                                        // model
  890.         fOutput->Write(aRefNum,string);
  891.  
  892. //    Segment Data    ................................    
  893.         i = sprintf(string,"%d",(fPointMatrix->fLeft->GetNumberSegments()));
  894.         sprintf(string+i,"%s",sEnd);                                                        // model
  895.         fOutput->Write(aRefNum,string);
  896.         fPointMatrix->fLeft->WBack(fOutput, aRefNum, sEnd,(fSolution[0]-1));    // write segment data backward
  897.  
  898.         i = sprintf(string,"%d",(fPointMatrix->fRight->GetNumberSegments()));
  899.         sprintf(string+i,"%s",sEnd);                                                        // add line terminator
  900.         fOutput->Write(aRefNum,string);
  901.         fPointMatrix->fRight->WBack(fOutput, aRefNum, sEnd,(fSolution[0]-1));    // write segment data backward
  902.  
  903.         i = sprintf(string,"%d",(fPointMatrix->fBottom->GetNumberSegments()));
  904.         sprintf(string+i,"%s",sEnd);                                                        // add line terminator
  905.         fOutput->Write(aRefNum,string);
  906.         fPointMatrix->fBottom->WForward(fOutput, aRefNum, sEnd,(fSolution[0]-1));    // write segment data forward
  907.  
  908.         i = sprintf(string,"%d",(fPointMatrix->fTop->GetNumberSegments()));
  909.         sprintf(string+i,"%s",sEnd);                                                        // add line terminator
  910.         fOutput->Write(aRefNum,string);
  911.         fPointMatrix->fTop->WForward(fOutput, aRefNum, sEnd,(fSolution[0]-1));        // write segment data forward
  912.     
  913. //    Interior Data    ................................    
  914.         WallRecord data;
  915.         data = fInterior->GetData();                                                        // get data for interior
  916.         i = sprintf(string,"%f ",data.u);                                                // u            -    u velocity
  917.         i += sprintf(string+i,"%f ",data.v);                                        // v            -    v velocity
  918.         i += sprintf(string+i,"%f ",data.w);                                        // w        -    w velocity
  919.         i += sprintf(string+i,"%f",data.density);                                // rh        -    density
  920.         sprintf(string+i,"%s",sEnd);                                                        // add line terminator
  921.         fOutput->Write(aRefNum,string);                                                    // write the string
  922.                 
  923.         i = sprintf(string,"%f ",data.temp);                                            // t            -    temperature
  924.         i += sprintf(string+i,"%f ",data.kenergy);                                // tk        -    kinetic energy
  925.         i += sprintf(string+i,"%f ",data.dissip);                                    // td        -    dissipation
  926.         i += sprintf(string+i,"%f ",data.mixfrac);                                // f            -    mixture fraction
  927.         i += sprintf(string+i,"%f ",data.concfrac);                                // g            -    concentration fraction
  928.         i += sprintf(string+i,"%f",data.fuelfrac);                                    // fu        -    fuel fraction
  929.         sprintf(string+i,"%s",sEnd);                                                    // add line terminator
  930.         fOutput->Write(aRefNum,string);                                                // write the string
  931.                 
  932.         i = sprintf(string,"%f ",fTempFuel);                                            // tfuel    -    temperature of fuel
  933.         i += sprintf(string+i,"%f",fTempAir);                                        // tair        -    temperature of air
  934.         sprintf(string+i,"%s",sEnd);                                                    // add line terminator
  935.         fOutput->Write(aRefNum,string);                                                // write the string
  936.  
  937. //    Prandtl Numbers    ................................    
  938.         i = 0;
  939.         for (x = 0; x< 10; x++)
  940.             i += sprintf(string+i,"%f ",fPran[x]);                                    // prl        -    prandlt numbers
  941.         i += sprintf(string+i,"%f",fPran[10]);
  942.         sprintf(string+i,"%s",sEnd);                                                    // add line terminator
  943.         fOutput->Write(aRefNum,string);
  944.         fOutput->Write(aRefNum,string);                                                // prt        -    prandlt numbers
  945.     
  946. //    Relaxation Numbers    ................................    
  947.         i = sprintf(string,"%f ",fRelax[0]);                                            // relx    1    -     u velocity
  948.         i += sprintf(string+i,"%f ",fRelax[1]);                                        // relx2    -    v velocity
  949.         i += sprintf(string+i,"%f ",fRelax[2]);                                        // relx    3    -    pressure
  950.         i += sprintf(string+i,"%f ",fRelax[3]);                                        // relx4    -    w velocity
  951.         i += sprintf(string+i,"%f ",fRelax[6]);                                        // relx5    -    h = scalar
  952.         i += sprintf(string+i,"%f ",fRelax[4]);                                        // relx6    -    kinetic energy
  953.         i += sprintf(string+i,"%f ",fRelax[4]);                                        // relx7    -    dissipation = kenergy
  954.         i += sprintf(string+i,"%f ",fRelax[6]);                                        // relx8    -    f = scalar
  955.         i += sprintf(string+i,"%f ",fRelax[6]);                                        // relx9    -    fu = scalar
  956.         i += sprintf(string+i,"%f ",fRelax[6]);                                        // relx10    -    g = scalar
  957.         i += sprintf(string+i,"%f",fRelax[5]);                                        // relx11    -    density
  958.         sprintf(string+i,"%s",sEnd);                                                    // add line terminator
  959.         fOutput->Write(aRefNum,string);                                                // write the string
  960.     
  961. //    Sweep Numbers    ................................    
  962.         i = sprintf(string,"%ld ",fSolution[1]);                                        // nswp1    -     momentum
  963.         i += sprintf(string+i,"%ld ",fSolution[1]);                                // nswp2    -     momentum
  964.         i += sprintf(string+i,"%ld ",fSolution[2]);                                // nswp3    -     pressure corrections
  965.         i += sprintf(string+i,"%ld ",fSolution[1]);                                // nswp4    -     momentum
  966.         i += sprintf(string+i,"%ld ",fSolution[3]);                                // nswp5    -     scalar
  967.         i += sprintf(string+i,"%ld ",fSolution[3]);                                // nswp6    -     scalar
  968.         i += sprintf(string+i,"%ld ",fSolution[3]);                                // nswp7    -     scalar
  969.         i += sprintf(string+i,"%ld ",fSolution[3]);                                // nswp8    -     scalar
  970.         i += sprintf(string+i,"%ld ",fSolution[3]);                                // nswp9    -     scalar
  971.         i += sprintf(string+i,"%ld ",fSolution[3]);                                // nswp10-     scalar
  972.         i += sprintf(string+i,"%ld",fSolution[3]);                                    // nswp11-     scalar
  973.         sprintf(string+i,"%s",sEnd);                                                    // add line terminator
  974.         fOutput->Write(aRefNum,string);                                                // write the string
  975.     
  976. //    Print Variables    ................................    
  977.         this->DecodeParam(12,printOpt,fPrintOpts);                            // decode the print parameters
  978.         i = 0;
  979.         for (x = 0; x < 11; x++)
  980.             i += sprintf(string+i,"%d ",printOpt[x]);                                // iprint    -    print variables
  981.         i += sprintf(string+i,"%d",printOpt[11]);
  982.         sprintf(string+i,"%s",sEnd);                                                    // add line terminator
  983.         fOutput->Write(aRefNum,string);                                                // write the string
  984.     
  985. //    miscellaneous    ................................    
  986.         i = sprintf(string,"%f ",fPressure);                                            // refp        -    system pressure
  987.         i += sprintf(string+i,"%f",data.visc);                                        // vscty    -    internal viscosity
  988.         sprintf(string+i,"%s",sEnd);                                                    // add line terminator
  989.         fOutput->Write(aRefNum,string);                                                // write the string
  990.     
  991.         i = sprintf(string,"%d ",fIteration);                                            // maxi    -    max iterations
  992.         i += sprintf(string+i,"%f",fSolutionAccuracy);                            // tolr        -    solution accuracy
  993.         sprintf(string+i,"%s",sEnd);                                                    // add line terminator
  994.         fOutput->Write(aRefNum,string);                                                // write the string
  995.     
  996.         i = sprintf(string,"%.4f",fBoundryRadius);                                // rn        -    boundry radius
  997.         sprintf(string+i,"%s",sEnd);                                                    // add line terminator
  998.         fOutput->Write(aRefNum,string);                                                // write the string
  999.  
  1000. //    Obstacles & Baffles    ................................    
  1001.         i = sprintf(string,"%d ",fPointMatrix->GetNumBaffle(true));    // number of vertical baffles
  1002.         i += sprintf(string+i,"%d ",fPointMatrix->GetNumBaffle(false)); // number of horizontal baffles
  1003.         i += sprintf(string+i,"%d",fPointMatrix->GetNumObstacle());    // number of obstacles
  1004.         sprintf(string+i,"%s",sEnd);                                                    // add line terminator
  1005.         fOutput->Write(aRefNum,string);                                                // write the string
  1006.         fPointMatrix->WriteBaffles(true, fOutput, aRefNum);                // write segment data forward
  1007.         fPointMatrix->WriteBaffles(false, fOutput, aRefNum);                // write segment data forward
  1008.         fPointMatrix->WriteObstacles(fOutput, aRefNum);                    // write segment data forward
  1009.         
  1010.         }
  1011.  
  1012.     if (fExport == 3)
  1013.         fOutput->Write(0,"GRIDS NEXT");                                                // write to DTM
  1014.         
  1015.     if (fWriteGrid)
  1016.         fPointMatrix->WriteGrid(fOutput, aRefNum, fExport);                // write segment data
  1017.         
  1018.     if (fExport == 3)
  1019.         fOutput->Write(0,"DONE");                                                        // write to DTM
  1020.         
  1021.     delete string;
  1022.     }
  1023.  
  1024. // ****************************************************************
  1025. //    Modeless Dialog Window Methods
  1026. // ****************************************************************
  1027. // -----------------------------------------------------------------------------------------
  1028. //    Find the segment that contains theMouse.
  1029. // -----------------------------------------------------------------------------------------
  1030. void TCFDFrontDocument::SetDialogOn (Boolean theState, short dbox)
  1031.     {
  1032.     long t, t1;                                                                                    // temporary vars
  1033.  
  1034.     t = pow(2, (dbox-1));                                                                // value of a specific bit
  1035.     t1 = fDialogOn & t;                                                                    // = 0 if not on = t if on
  1036.     if (theState && t1 == 0)                                                        // set to true (window is open)
  1037.         fDialogOn += t;
  1038.     else if (!theState && t1 == t)                                            // set to false (window is closed)
  1039.         fDialogOn -= t;
  1040.         
  1041.     return;
  1042.     }
  1043.  
  1044. // -----------------------------------------------------------------------------------------
  1045. //    Find the segment that contains theMouse.
  1046. // -----------------------------------------------------------------------------------------
  1047. Boolean TCFDFrontDocument::IsDialogOn (short dbox)
  1048.     {
  1049.     long t, t1;                                                                                    // temporary vars
  1050.  
  1051.     t = pow(2,(dbox-1));                                                                // bit value of this dialog box
  1052.     t1 = fDialogOn & t;                                                                    // = 0 if off ; = t if on
  1053.     if (t1 == t)                                                                                // is bit on?
  1054.         return true;                                                                            // yes
  1055.     return false;                                                                                // no
  1056.     }
  1057.  
  1058. // ------------------------------------------------------------------------------------------
  1059. //    Decode the print options long int
  1060. // ------------------------------------------------------------------------------------------
  1061. void TCFDFrontDocument::DecodeParam(short index, Boolean * param, long decodeVal)
  1062.     {
  1063.     long t,temp;
  1064.     
  1065.     temp = decodeVal;                                                                                // get data for Flow
  1066.     while (index >= 0)                                                                                // check all bits
  1067.         {
  1068.         t = pow(2,index);                                                                            // t = (2)^index power
  1069.         if ((temp - t) >= 0)                                                                        // is this param on?
  1070.             {
  1071.             param[index] = true;                                                                // yes: set true
  1072.             temp -= t;                                                                                // reset temp for next index
  1073.             }
  1074.         else            
  1075.             param[index] = false;                                                                // no: set false
  1076.         index--;                                                                                        // next param
  1077.         }
  1078.     return;
  1079.     }
  1080.         
  1081. // ------------------------------------------------------------------------------------------
  1082. //    Decode the print options long int
  1083. // ------------------------------------------------------------------------------------------
  1084. void TCFDFrontDocument::EncodeParam(short index, Boolean * param, long * decodeVal)
  1085.     {
  1086.     short     t;
  1087.     long         temp;
  1088.     
  1089.     *decodeVal = 0L;
  1090.     for (t = 0; t < index; t++)
  1091.         {
  1092.         if (param[t])
  1093.             {
  1094.             temp = pow(2,t);
  1095.             *decodeVal += temp;
  1096.             }
  1097.         }
  1098.     return;
  1099.     }
  1100.         
  1101. // ****************************************************************
  1102. //    Print Parameters Dialog
  1103. // ****************************************************************
  1104. // ------------------------------------------------------------------------------------------
  1105. //    Initialize the print options menu dialog
  1106. // ------------------------------------------------------------------------------------------
  1107. void TCFDFrontDocument::MakeFortranWindow(void)
  1108.     {    
  1109.     TWindow             * aWindow;
  1110.     TScroller            *    sView;
  1111.     TFortranView     *    fortView;
  1112.         
  1113.     aWindow = NewTemplateWindow(1019, ((TDocument *) this));        // create window
  1114.     aWindow->Open();                                                                                        // open window
  1115.     fortView = (TFortranView *) (aWindow->FindSubView('fort'));    // get reference to window
  1116.     sView = (TScroller *) (aWindow->FindSubView('VW01'));    // get reference to window
  1117.  
  1118.     aWindow->Select();
  1119.     fortView->AutoScrolling (TRUE);
  1120.     sView->fScrollBars[0]->Activate (TRUE);
  1121.     sView->fScrollBars[1]->Activate (TRUE);
  1122.     aWindow->Update();
  1123.     gFortranView = fortView;    
  1124.     return;    
  1125.     }
  1126.     
  1127. // ****************************************************************
  1128. //    Print Parameters Dialog
  1129. // ****************************************************************
  1130. // ------------------------------------------------------------------------------------------
  1131. //    Initialize the print options menu dialog
  1132. // ------------------------------------------------------------------------------------------
  1133. void TCFDFrontDocument::MakeOptPrint(void)
  1134.     {    
  1135.     TWindow * aWindow;
  1136.     Boolean checkBox[13];
  1137.     
  1138.     if (this->IsDialogOn(cPrintDialog))                                                    // if already open 
  1139.         {
  1140.         optPrint->BringToFront();                                                                    // bring window to the front
  1141.         return;
  1142.         }
  1143.         
  1144.     aWindow = NewTemplateWindow(kOptPrint, ((TDocument *) this));    // create window
  1145.     aWindow->Open();                                                                                        // open window
  1146.     optPrint = (TOptPrint *) (aWindow->FindSubView('DP03'));        // get reference to window
  1147.     
  1148.     this->SetDialogOn(true,cPrintDialog);                                                // turn dialog on
  1149.     this->DecodeParam(12,checkBox,fPrintOpts);                                    // figure which check boxes are on
  1150.     optPrint->MarkCheckBox(checkBox);                                                        // mark the boxes
  1151.     return;    
  1152.     }
  1153.     
  1154. // ****************************************************************
  1155. //    Flow Parameters Dialog
  1156. // ****************************************************************
  1157. // ------------------------------------------------------------------------------------------
  1158. //    Initialize the Flow options menu dialog
  1159. // ------------------------------------------------------------------------------------------
  1160. void TCFDFrontDocument::MakeOptFlow(void)
  1161.     {    
  1162.     TWindow * aWindow;
  1163.     Boolean radioButton[15];
  1164.     
  1165.     if (this->IsDialogOn(cFlowDialog))                                                        // if already open 
  1166.         {
  1167.         optFlow->BringToFront();                                                                // bring window to the front
  1168.         return;
  1169.         }
  1170.         
  1171.     aWindow = NewTemplateWindow(kOptFlow, ((TDocument *) this));    // create window
  1172.     aWindow->Open();                                                                                // open window
  1173.     optFlow = (TOptFlow *) (aWindow->FindSubView('FLOW'));                // get reference to window
  1174.     
  1175.     this->SetDialogOn(true,cFlowDialog);                                                // turn dialog on
  1176.     this->DecodeParam(14,radioButton,fFlowOpts);                                // figure which check boxes are on
  1177.     optFlow->MarkRadioButton(radioButton);                                            // mark the boxes
  1178.     return;    
  1179.     }
  1180.     
  1181. // ------------------------------------------------------------------------------------------
  1182. //    Initialize the Premix options menu dialog
  1183. // ------------------------------------------------------------------------------------------
  1184. void TCFDFrontDocument::SetPremixOpts(float b, short c, extended p, float p8, float p9, float p5)
  1185.     {    
  1186.     fBreakup = b;
  1187.     fCompress = c;
  1188.     fPressure = p;
  1189.     fPran[7] = p8;
  1190.     fPran[8] = p9;
  1191.     fPran[4] = p5;
  1192.     return;
  1193.     }
  1194.     
  1195. // ------------------------------------------------------------------------------------------
  1196. //    Initialize the Premix options menu dialog
  1197. // ------------------------------------------------------------------------------------------
  1198. void TCFDFrontDocument::GetPremixOpts(float * b, short * c, extended * p, float * p8, float * p9, float * p5)
  1199.     {    
  1200.     *b     = fBreakup;
  1201.     *c    = fCompress;
  1202.     *p    = fPressure;
  1203.     *p8     = fPran[7];
  1204.     *p9     = fPran[8];
  1205.     *p5     = fPran[4];
  1206.     return;
  1207.     }
  1208.  
  1209. // ------------------------------------------------------------------------------------------
  1210. //    Initialize the Premix options menu dialog
  1211. // ------------------------------------------------------------------------------------------
  1212. void TCFDFrontDocument::SetDiffusionOpts(short fuel, short cmp, extended p, float p8, float p10, float tA, float tF)
  1213.     {    
  1214.     fFuel                = fuel;
  1215.     fCompress    = cmp;
  1216.     fTempAir        = tA;
  1217.     fTempFuel        = tF;
  1218.     fPressure     = p;
  1219.     fPran[7]        = p8;
  1220.     fPran[9]        = p10;
  1221.     return;
  1222.     }
  1223.     
  1224. // ------------------------------------------------------------------------------------------
  1225. //    Initialize the Premix options menu dialog
  1226. // ------------------------------------------------------------------------------------------
  1227. void TCFDFrontDocument::GetDiffusionOpts(short * fuel, short * cmp, extended * p, float * p8, float * p10, float * tA, float * tF)
  1228.     {    
  1229.     *fuel    = fFuel;
  1230.     *cmp    = fCompress;
  1231.     *tA        = fTempAir;
  1232.     *tF        = fTempFuel;
  1233.     *p        = fPressure;
  1234.     *p8        = fPran[7];
  1235.     *p10    = fPran[9];
  1236.     return;
  1237.     }
  1238.  
  1239. // ------------------------------------------------------------------------------------------
  1240. //    Initialize the Premix options menu dialog
  1241. // ------------------------------------------------------------------------------------------
  1242. void TCFDFrontDocument::SetTurbulenceOpts(float p6, float p7)
  1243.     {    
  1244.     fPran[5]    = p6;
  1245.     fPran[6]    = p7;
  1246.     return;
  1247.     }
  1248.     
  1249. // ------------------------------------------------------------------------------------------
  1250. //    Initialize the Premix options menu dialog
  1251. // ------------------------------------------------------------------------------------------
  1252. void TCFDFrontDocument::GetTurbulenceOpts(float * p6, float * p7)
  1253.     {    
  1254.     *p6        = fPran[5];
  1255.     *p7        = fPran[6];
  1256.     return;
  1257.     }
  1258.  
  1259. // ------------------------------------------------------------------------------------------
  1260. //    Initialize the Premix options menu dialog
  1261. // ------------------------------------------------------------------------------------------
  1262. void TCFDFrontDocument::SetPressureOpts(extended p, float p5)
  1263.     {    
  1264.     fPressure    = p;
  1265.     fPran[4] = p5;
  1266.     return;
  1267.     }
  1268.     
  1269. // ------------------------------------------------------------------------------------------
  1270. //    Initialize the Premix options menu dialog
  1271. // ------------------------------------------------------------------------------------------
  1272. void TCFDFrontDocument::GetPressureOpts(extended * p, float * p5)
  1273.     {    
  1274.     *p = fPressure;
  1275.     *p5 = fPran[4];
  1276.     return;
  1277.     }
  1278.  
  1279. // ****************************************************************
  1280. //    Solution Parameters Dialog
  1281. // ****************************************************************
  1282. // ------------------------------------------------------------------------------------------
  1283. //    Initialize the Flow options menu dialog
  1284. // ------------------------------------------------------------------------------------------
  1285. void TCFDFrontDocument::MakeOptSolution(void)
  1286.     {    
  1287.     TWindow * aWindow;
  1288.     if (this->IsDialogOn(cSolutionDialog))                                                    // if already open 
  1289.         {
  1290.         optSol->BringToFront();                                                                                // bring window to the front
  1291.         return;    
  1292.         }
  1293.         
  1294.     aWindow = NewTemplateWindow(kOptSolution, ((TDocument *) this));    // create window
  1295.     aWindow->Open();                                                                                                // open window
  1296.     optSol = (TOptSolution *) (aWindow->FindSubView('DP06'));                // get reference to window
  1297.     
  1298.     this->SetDialogOn(true,cSolutionDialog);                                                // turn dialog on
  1299.     optSol->MarkScroller(fSolution,fSolutionAccuracy,fIteration);
  1300.     return;    
  1301.     }
  1302.     
  1303. // ------------------------------------------------------------------------------------------
  1304. //    Initialize the Flow options menu dialog
  1305. // ------------------------------------------------------------------------------------------
  1306. void TCFDFrontDocument::SetSolutionOpts(Boolean scroller, short index, long value, float value1,short value2)
  1307.     {
  1308.     if (scroller)
  1309.         {
  1310.         if (index-1 == 0 && fPointMatrix->GetFineGrid())
  1311.             fPointMatrix->ShowFineGrid();
  1312.         fSolution[index-1] = value;                                                                    // levels set with scrollers
  1313.         
  1314.         if (index-1 == 0 && fPointMatrix->GetFineGrid())
  1315.             fPointMatrix->ShowFineGrid();
  1316.         }
  1317.     else
  1318.         {
  1319.         fSolutionAccuracy = value1;                                                                    // solution accuracy
  1320.         fIteration = value2;
  1321.         }
  1322.     }
  1323.     
  1324. // ****************************************************************
  1325. //    Solution Parameters Dialog
  1326. // ****************************************************************
  1327. // ------------------------------------------------------------------------------------------
  1328. //    Initialize the Flow options menu dialog
  1329. // ------------------------------------------------------------------------------------------
  1330. void TCFDFrontDocument::MakeOptRelax(void)
  1331.     {    
  1332.     TWindow * aWindow;
  1333.     if (this->IsDialogOn(cRelaxDialog))                                                        // if already open 
  1334.         {
  1335.         optRelax->BringToFront();                                                                        // bring window to the front
  1336.         return;
  1337.         }
  1338.         
  1339.     aWindow = NewTemplateWindow(kOptRelax, ((TDocument *) this));    // create window
  1340.     aWindow->Open();                                                                                // open window
  1341.     optRelax = (TRelax *) (aWindow->FindSubView('relx'));                    // get reference to window
  1342.     
  1343.     this->SetDialogOn(true,cRelaxDialog);                                                // turn dialog on
  1344.     optRelax->MarkScroller(fRelax);
  1345.     return;    
  1346.     }
  1347.     
  1348. // ****************************************************************
  1349. //    Dimensions Dialog
  1350. // ****************************************************************
  1351. // ------------------------------------------------------------------------------------------
  1352. //    Initialize the Dimensions menu dialog
  1353. // ------------------------------------------------------------------------------------------
  1354. void TCFDFrontDocument::GetRemoteApp(void)
  1355.     {    
  1356.     TWindow            * aWindow;
  1357.     TAppDialog    * theApp;
  1358.     
  1359.     aWindow = NewTemplateWindow(1018, ((TDocument *) this));                     // create window
  1360.     theApp = (TAppDialog *) (aWindow->FindSubView('parm'));                        // get reference to window
  1361.     HLock((Handle) this);
  1362.         theApp->GetApp(fRemoteApplication);
  1363.     HUnlock((Handle) this);
  1364.     return;    
  1365.     }
  1366.     
  1367. // ------------------------------------------------------------------------------------------
  1368. //    Set the dimensions for the geometry
  1369. // ------------------------------------------------------------------------------------------
  1370. void TCFDFrontDocument::SetApp(char * app)
  1371.     {
  1372.     if (strlen(app) > 511)
  1373.         app[511] = 0;
  1374.     
  1375.     strcpy(fRemoteApplication,app);
  1376.     return;
  1377.     }
  1378.  
  1379. // ****************************************************************
  1380. //    Dimensions Dialog
  1381. // ****************************************************************
  1382. // ------------------------------------------------------------------------------------------
  1383. //    Initialize the Dimensions menu dialog
  1384. // ------------------------------------------------------------------------------------------
  1385. void TCFDFrontDocument::GetImageName(void)
  1386.     {    
  1387.     TWindow                * aWindow;
  1388.     TImageDialog    * theApp;
  1389.     
  1390.     aWindow = NewTemplateWindow(1020, ((TDocument *) this));                     // create window
  1391.     theApp = (TImageDialog *) (aWindow->FindSubView('imge'));                        // get reference to window
  1392.     HLock((Handle) this);
  1393.         theApp->GetImage(fImageName);
  1394.     HUnlock((Handle) this);
  1395.     return;    
  1396.     }
  1397.     
  1398. // ------------------------------------------------------------------------------------------
  1399. //    Set the dimensions for the geometry
  1400. // ------------------------------------------------------------------------------------------
  1401. void TCFDFrontDocument::SetImageName(char * app)
  1402.     {
  1403.     if (strlen(app) > 511)
  1404.         app[511] = 0;
  1405.     
  1406.     strcpy(fImageName,app);
  1407.     return;
  1408.     }
  1409.  
  1410. // ****************************************************************
  1411. //    Dimensions Dialog
  1412. // ****************************************************************
  1413. // ------------------------------------------------------------------------------------------
  1414. //    Initialize the Dimensions menu dialog
  1415. // ------------------------------------------------------------------------------------------
  1416. void TCFDFrontDocument::GetDims(void)
  1417.     {    
  1418.     TWindow        * aWindow;
  1419.     TDimension    * theDim;
  1420.     
  1421.     aWindow = NewTemplateWindow(kOptDimension, ((TDocument *) this)); // create window
  1422.     theDim = (TDimension *) (aWindow->FindSubView('dims'));                    // get reference to window
  1423.     if (!theDim->GetDimensions())
  1424.         {
  1425.         TQuitCommand * q;
  1426.         q = new TQuitCommand;
  1427.         FailNIL(q);
  1428.         q->IQuitCommand(cQuit);
  1429.         gCFDFrontApplication->PostCommand(q); 
  1430.         }
  1431.     return;    
  1432.     }
  1433.     
  1434. // ------------------------------------------------------------------------------------------
  1435. //    Set the dimensions for the geometry
  1436. // ------------------------------------------------------------------------------------------
  1437. void TCFDFrontDocument::SetDimensions(float width, float height)
  1438.     {
  1439.     fWidth = width;
  1440.     fHeight = height;
  1441.     return;
  1442.     }
  1443.  
  1444. // ------------------------------------------------------------------------------------------
  1445. //    Set the dimensions for the geometry
  1446. //    mangled name: ShowL__FPc
  1447. // ------------------------------------------------------------------------------------------
  1448. void test(void)
  1449.     {
  1450.     gFortranView->PutLine("This is a test");
  1451.     }
  1452.  
  1453. // ------------------------------------------------------------------------------------------
  1454. //    Set the dimensions for the geometry
  1455. //    mangled name: ShowL__FPc
  1456. // ------------------------------------------------------------------------------------------
  1457. void ShowL(char * msg)
  1458.     {
  1459.     short len;
  1460.     char  * msg1;
  1461.     
  1462.     len = strlen(msg);
  1463.     msg1 = new char[len+2];
  1464.     strcpy(msg1,msg);
  1465.     msg1[len] = '\n';
  1466.     msg1[len+1] = 0;
  1467.     gFortranView->PutLine(msg1);
  1468.     }
  1469.  
  1470. // ------------------------------------------------------------------------------------------
  1471. //    Set the dimensions for the geometry
  1472. //    mangled name: StopKey__Fv
  1473. // ------------------------------------------------------------------------------------------
  1474. short StopKey(void)
  1475.     {
  1476.     long    key;
  1477.     char    msg[80];
  1478.  
  1479.     if (GetOSEvent(keyDownMask,gEvent))
  1480.         {
  1481.         key = BitAnd(gEvent->message,charCodeMask);
  1482.         sprintf(msg,"Got Key %c\n",key);
  1483.         gFortranView->PutLine(msg);
  1484.         gStop = 1;
  1485.         if (key == 46 && gEvent->modifiers & cmdKey)
  1486.             return 1;
  1487.         }
  1488.     return 0;
  1489.     }
  1490.  
  1491. // ------------------------------------------------------------------------------------------
  1492. //    Set the dimensions for the geometry
  1493. //    mangled name: StopKey__Fv
  1494. // ------------------------------------------------------------------------------------------
  1495. void SetStop(void)
  1496.     {
  1497.     gStop = 1;
  1498.     }
  1499.